<?php 
	require_once('connectDB.php');
	$sql = 'SELECT email FROM email';
	$elist = mysql_query($sql) or die(mysql_error());
	$area = "";
	while($rows = mysql_fetch_assoc($elist))
	{
		$area .= $rows['email'].',';
	}
	// read list of email from files 
	$email_list = explode(',',$area);
	// Count how many emails theres are 
	$total_email = count($email_list);
	//go through the list  and trim off the new line character
	for($counter=0;$counter<$total_email;$counter++)
	{
		$email_list[$counter] = trim($email_list[$counter]);
	}
	$to = $email_list;
	$subject = $_POST['ct_title'];
	$message = $_POST['ct_message'];
	$from = "vanlongdao@hotmail.com"." this is ".$_POST['ct_name'];
	$headers = "From:" . $from;
	for($i=0;$i<(count($to)-1);$i++)
	{
		
		$send = mail($to[$i],$subject,$message,$headers);
	}
	if($send)
	{
		echo "Mail Sent. ".$send;
	}
	else
	{
		echo "Can not send";
	}
	//print_r($to);
?>